<%@page import="com.bionic.banking.logic.controller.BankAccountController"%>
<%@page import="com.bionic.banking.core.entity.BankAccount" %>
<%@page language="java"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib uri="../WEB-INF/taglib.tld" prefix="m" %> 
<form method="post" action="../bankaccount/Update.jsp">     
  <table border="3">
       <h3> Edit bank account </h3>
        <%
            Integer id= Integer.valueOf(request.getParameter("id"));        
            try 
            {
                BankAccountController bean = new BankAccountController();
                BankAccount account = bean.getDetails(id);           
        %>        
        <jsp:useBean id="customerBean" class="com.bionic.banking.logic.controller.CustomerController" />
        <jsp:useBean id="domainHelperBean" class="com.bionic.banking.logic.DomainUtil" />
        <tr>
            <td>Account Id</td>
            <td>
                <input id="id" name="id" value="${param.id}" readonly="true" style="background: transparent"/>
            </td>
            <td>Customer</td>
            <td>                 
                <c:set var="customerId" value="<%= account.getCustomerId() %>" />
                <input id="customerId" name="customerId" value="${customerId}" hidden="true" />  
                <a href="javascript:viewCustomerRecord(${customerId});">
                    ${customerBean.getDetails(customerId)}</a>
            </td> 
        </tr>
        <tr>
            <td>Type</td>
            <td>
                <input id = "accountType" name="accountType" style="background: transparent"
                       value="<%= account.getAccountType() %>" readonly="true" />
            </td>
            <td>Description</td>
            <td><input id="description" name="description" value="<%= account.getDescription() %>" /></td>
        </tr>                  
        <tr>
            <td>Balance</td>
            <td><input  id="balance" name="balance" value="<%= account.getBalance() %>" 
                        <m:maskedInput mask="^[0-9]{0,10}[.]?[0-9]{0,10}$"/> /> </td>
            <td>Credit line</td>
            <td><input id = "creditLine" name="creditLine" 
                       value="<%= account.getCreditLine() %>"  
                       <m:maskedInput mask="^[0-9]{0,10}[.]?[0-9]{0,10}$"/> /></td>
        </tr>
        <tr>
            <td>Currency</td>
            <c:set var="currencyCode" value="<%= account.getCurrencyId() %>" />            
            <td>
                <input id="currencyId" name="currencyId" hidden="true" value="${currencyCode}"/>
                <input id = "currency" name="currency" readonly="true" style="background: transparent"
                       value="${domainHelperBean.getCurrencyByCode(currencyCode).getSymbol()}"/>
            </td>
            <td>Created on</td>
            <td >
                <input readonly="true" type="datetime" id = "createdon" name="createdon"
                       value="<%= account.getCreatedon() %>" style="background: transparent"/>
            </td>
        </tr>

        <%    
        }
        catch(Exception e)
        {
            System.out.println(e);//TODO: logger
            //alert("error " + e);
        }
        %>
   </table>
            <br/>
            <input type="submit" name="Submit" value="Update" >
            <a href="Controller?command=viewBankAccountsList"><strong>Go to List</strong></a>          
</form>